import {request} from '../../request/http'

Page({

  /**
   * 页面的初始数据
   */
  data: {
    
    categoriesList:[],
     //分类数据
     leftMenuList:[],
     // 右侧的商品数据
     rightContent: [],
     //tab切换
     currentIndex:0,
    
  },

  /**
   * 生命周期函数--监听页面加载
   */





  onLoad:async function(options) {
      // 获取商品分类数据
    const res = await request({ url: "categories" });
    console.log('分类数据',res);
    wx.setStorageSync('cates', {time:Date.now(),data:res.message})
    if(res.meta.status==200){
        this.categoriesList=res.message
    }
    let leftMenuList=this.categoriesList.map(item=>item.cat_name)
    let rightContent=this.categoriesList[0].children;
    this.setData({
      leftMenuList,  
      rightContent,
     
    })

  },

 
   //点击tab进行切换
 handleItemTap(e){
  console.log('当前索引',e);
  let index=e.target.dataset.index
  let rightContent=this.categoriesList[index].children
  console.log('右侧内容',rightContent);
  this.setData({
    rightContent:rightContent,
    
  })
},
})